package com.socket.socketMoreTest;

import com.socket.socketObjTest.Pet;

import java.io.*;
import java.net.Socket;

/**
 * ServerThreadPet--bdqnPractice
 *
 * @author: Jovi
 * @createTime: 2017-09-14 11:18
 **/
public class ServerThreadPet implements Runnable{

    Socket socket;

    public ServerThreadPet(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {

        try {
            InputStream is = socket.getInputStream();
            ObjectInputStream ois = new ObjectInputStream(is);

            OutputStream os = socket.getOutputStream();
            PrintWriter pw = new PrintWriter(os);

            Pet pet = (Pet) ois.readObject();
            System.out.println(pet);

            String repay = "congratulations";

            pw.write(repay);
            pw.flush();
            pw.close();
            os.close();
            ois.close();
            is.close();
            socket.close();

        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }


}
